import java.security.PublicKey;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class TreeSetTest {
    public static void main(String[] args) {
        Set<A> treeSet= new TreeSet<>();
        A a1 = new A(14);
        A a2 = new A(13);
        A a3 = new A(22);
        A a4 = new A(5);
        treeSet.add(a1);
        treeSet.add(a2);
        treeSet.add(a3);
        treeSet.add(a4);
        for (A e:treeSet) {
            System.out.println(e);
        }
        System.out.println("=================================");
     B b1 = new B(11);
     B b2 = new B(10);
     B b3 = new B(1);
     B b4 = new B(22);
     Set<B> set2= new TreeSet<>(new myComparator());
     set2.add(b1);
        set2.add(b2);
        set2.add(b3);
        set2.add(b4);
        for(B e : set2) {
            System.out.println(e);
        }


    }
}
class myComparator implements Comparator<B> {

    @Override
    public int compare(B o1, B o2) {
        return o1.i -o2.i;
    }
}








class A implements Comparable<A>{
    int i;

    public A(int i) {
        this.i = i;
    }

    @Override
    public int compareTo(A o) {
        return o.i-this.i;
    }

    @Override
    public String
    toString() {
        return "A{" +
                "i=" + i +
                '}';
    }

}
class B {
    int i;

    public B(int i) {
        this.i = i;
    }

    public B() {
    }

    @Override
    public String toString() {
        return "B{" +
                "i=" + i +
                '}';
    }
}